﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsFormsApplication5
{
    public class Draw
    {
        Data data;
        string dir = " ", fulldir = " ";
        PictureBox MainPicBox; 
        public Draw(PictureBox PicBox)
        {
            MainPicBox = PicBox;
             data = new Data();
        }

     
        public void Add( Rectangle tank, List<PictureBox> listDraw, PictureBox Mainpixbox)
        {
            PictureBox picturebox = new PictureBox();
            picturebox.Size = new Size(tank.Width, tank.Height);
            picturebox.Location = new Point(tank.Location.X, tank.Location.Y);
            listDraw.Add(picturebox);
            Mainpixbox.Controls.Add(picturebox);
        }

        public void Image(  List<PictureBox> listDraw, string dir, Rectangle rect )
        {
            for (int i = 0; i < listDraw.Count; i++)
            {
                if ((listDraw[i].Location.X == rect.Location.X)
                    && (listDraw[i].Location.Y == rect.Location.Y))
                {
                    if (dir != "")
                    {
                        Bitmap mybit1 = new Bitmap(dir);
                        mybit1.MakeTransparent(Color.FromArgb(255, 255, 255));
                        listDraw[i].Image = mybit1;
                        MainPicBox.Controls.Add(listDraw[i]);
                    }
                    else
                    {
                        listDraw[i].BackColor = Color.Red;
                        MainPicBox.Controls.Add(listDraw[i]);
                    }
                    
                }
            }
            
            MainPicBox.Invalidate();

        }
        public void MoveDraw(List<PictureBox> listDraw, Rectangle rect, int numberofenemy)
        {
            listDraw[numberofenemy].Location = new Point(rect.Location.X, rect.Location.Y);
            MainPicBox.Invalidate();
        }

        public void Delete( List<PictureBox> listDraw, Rectangle rect)
        {
            //Console.WriteLine("Delete method " + Convert.ToString(listDraw.Count));
            //Console.WriteLine("Delete method X " + Convert.ToString(rect.Location.X) + " Y " + Convert.ToString(rect.Location.Y));
 

            for (int i = 0; i < listDraw.Count; i++)
            {
                if ((listDraw[i].Location.X == rect.Location.X)
                    && (listDraw[i].Location.Y == rect.Location.Y))
                {
                    listDraw[i].Dispose();
                    listDraw.Remove(listDraw[i]);
                    break;
                }
            }
          // Console.WriteLine("End Delete method " + Convert.ToString(listDraw.Count));
           MainPicBox.Invalidate();
        }

    }
}
